#!/bin/sh
#
# Tue Nov 7 2000 Go Taniguchi <go@turbolinux.co.jp>
# Fri Feb 23 2001 Merlin Ma <merlin@turbolinux.com.cn>
#

function modinstall
{
    /sbin/modprobe $1
    if [ ! "$?" = "0" ]; then
	echo Install driver $1 error.
	exit 3
    fi
}

if [ ! "$DISPLAY" = "" ] ; then
    echo Can not run unicon under X.
    exit 1 
fi
if [ ! "$UID" = "0" ] ; then
    echo Can not install unicon drivers with non root user.
    exit 2
fi

if [ ! "$LC_ALL" = "" ] ; then
    UNICONLANG=$LC_ALL
elif [ ! "$LANG" == "" ] ; then
    UNICONLANG=$LANG
elif [ -e /etc/sysconfig/i18n ] ; then
    if grep -q GB18030 /etc/sysconfig/i18n ; then
	UNICONLANG=GBK
    elif grep -q GBK /etc/sysconfig/i18n ; then
	UNICONLANG=GBK
    elif grep -q GB /etc/sysconfig/i18n ; then
        UNICONLANG=GB2312
    elif grep -q TW /etc/sysconfig/i18n ; then
        UNICONLANG=BIG5
     elif grep -q ja /etc/sysconfig/i18n ; then
        UNICONLANG=JP
    elif grep -q ko /etc/sysconfig/i18n ; then
        UNICONLANG=KR
    else
        UNICONLANG=GBK
    fi
fi

if ! grep -q '[[:alnum:]]' /proc/fb ; then 
  modinstall vga16fb
fi
modinstall unikey
loadunimap /usr/lib/unicon/direct.uni

case $UNICONLANG in
	zh_CN.GB2312|GBK)
		modinstall encode-gbk 
		unicon --gbk 
		;;
	zh_CN.GBK|GBK)
		modinstall encode-gbk 
		unicon --gbk 
		;;
	zh_CN.GB2312|GB2312)
		modinstall encode-gb 
		unicon --gb 
		;;
	zh_TW.Big5|BIG5)
		modinstall encode-big5 
		unicon --big5
		;;
	ja*|JP)	
		modinstall encode-jis 
		unicon --jis
		;;
	ko*|KR)
		modinstall encode-kscm 
		unicon --kscm
		;;
	*)	
                modinstall encode-gbk
                unicon --gbk
esac

if [ -f /var/lock/subsys/gpm ] ; then
    /etc/rc.d/init.d/gpm restart 1>/dev/null 2>/dev/null
fi
exit 0
